<meta name="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
$(function(){
	var searchType = '${searchType}';
	$("#pro_li_orders").addClass("active");
	if(searchType=='1'){
		$("#pro_li_products").addClass("active");
		$("#pro_li_orders").removeClass("active");
		$("#product_search_cdts").show();
		$("#order_search_cdts").hide();
		$("#goodsList").show();
		$("#goodsOrderList").hide();
		$("#product_operator").show();
	}else{
		$("#pro_li_orders").addClass("active");
		$("#pro_li_products").removeClass("active");
		$("#order_search_cdts").show();
		$("#product_search_cdts").hide();
		$("#goodsList").hide();
		$("#goodsOrderList").show();
		$("#product_operator").hide();
	}
	$("#goodsTab .nav-tabs li a").click(function(e){
		e.preventDefault();//阻止a链接的跳转行为 
		$(this).tab("show");//显示当前选中的链接及关联的content
	});
});
</script>
<div class="panel-heading panel-result-title">
	<h3 class="panel-title">查询结果</h3>
	<div id="product_operator" class="btn-group btn-gp-default">
		<button id="btn_add" type="button" class="btn btn-default panel-radius-left">添加</button>
		<button id="btn_edit" type="button" class="btn btn-default panel-radius-none">修改</button>
		<button id="btn_delete" type="button" class="btn btn-default panel-radius-none">删除</button>
		<button id="btn_inventory" type="button" class="btn btn-default panel-radius-right">指定库存</button>
	</div>
</div>
<div id="goodsTab" class="container-fluid">
	<div class="row-fluid">
		<div class="span8">
			<ul class="nav nav-tabs pro_ul">
				<li id="pro_li_orders"><a href="#goodsOrderList">商品购买记录</a></li>
				<li id="pro_li_products"><a href="#goodsList">商品列表</a></li>
			</ul>
		</div>
	</div>
</div>
<div class="tab-content">
	<div id="goodsList" class="tab-pane">
		<!-- #set(PaginatedList<Goods> goods) -->
		<!--
		#set(
		pager = goods.pager,
		totalResults = pager.getCountOfTotalResults(),
		totalPages = pager.getCountOfTotalPages() * 1,
		pageSize = pager.pageSize,
		pageNo = pager.pageNo,
		prePageNo = pager.getPrevPageNo(),
		nextPageNo = pager.getNextPageNo()
		)
	-->
		<!--#if(goods)-->
		<table class="table table-bordered table-hover table-condensed tb" style="text-align: center;">
			<tr>
				<td class="td_ck tb-chose"><input type="checkbox" id="chkallIds"></td>
				<td class="tb-teacher">编号</td>
				<td>名称</td>
				<td class="tb-type">类型</td>
				<td class="tb-type">单价(元)</td>
				<td class="tb-type">库存</td>
				<td class="tb-type">状态</td>
				<td class="tb-long-time">创建日期</td>
			<tr>
				<!--#for(Goods good : goods)-->
			<tr>
				<td><input type="checkbox" id="chk_id" name="chk_name" value="${good.id}"></td>
				<td>${good.code}</td>
				<td>${good.name}</td>
				<td>${good.goodType.name}</td>
				<td>${good.price}</td>
				<td id="td_${good.id}">${good.counts}</td>
				<td>
					<!-- #if(good.status=='0') --> 上架 <!-- #else(good.status=='1') --> 下架 <!-- #end -->
				</td>
				<td>${good.createtime.format("yyyy-MM-dd")}</td>
			</tr>
			<!--#end-->
		</table>
		<div>
			<ul class="pagination">
				<li><a href="javascript:void(0);" onclick="goToPage(1,1)">首页</a></li>
				<!-- #if(pageNo==1) -->
				<li class="disabled"><a href="javascript:void(0);">上一页</a></li>
				<!-- #else -->
				<li><a href="javascript:void(0);" onclick="goToPage(1,${prePageNo})">上一页</a></li>
				<!-- #end -->
				<!-- #if(pageNo==totalPages) -->
				<li class="disabled"><a href="javascript:void(0);">下一页</a></li>
				<!-- #else -->
				<li><a href="javascript:void(0);" onclick="goToPage(1,${nextPageNo})">下一页</a></li>
				<!-- #end -->
				<li><a href="javascript:void(0);" onclick="goToPage(1,${totalPages})">尾页</a></li>
				<li><a>第<input id="txtPageNumber" value="${pageNo}" onkeyup="this.value=this.value.replace(/\D/g,'')" onchange="changePage(1,this.value)"
						onafterpaste="this.value=this.value.replace(/\D/g,'')" type="text" />页~&nbsp;共 ${totalPages}&nbsp;页/${totalResults}条
				</a></li>
			</ul>
		</div>
		<!-- #else -->
		
		<!-- #end -->
	</div>

	<!-- #set(PaginatedList<Order> orders) -->
	<!--
		#set(
		pager1 = orders.pager,
		totalResults1 = pager1.getCountOfTotalResults(),
		totalPages1 = pager1.getCountOfTotalPages() * 1,
		pageSize1 = pager1.pageSize,
		pageNo1 = pager1.pageNo,
		prePageNo1 = pager1.getPrevPageNo(),
		nextPageNo1 = pager1.getNextPageNo()
		)
-->

	<div id="goodsOrderList">
		<!-- #if(orders)-->
		<table class="table table-bordered table-hover table-condensed tb" style="text-align: center;">
			<tr>
				<td class="tb-chose">消费编号</td>
				<td class="tb-teacher">会员</td>
				<td>商品名称</td>
				<td class="tb-commoner">单价</td>
				<td class="tb-commoner">数量</td>
				<td class="tb-commoner">折扣</td>
				<td class="tb-commoner">价格</td>
				<td class="tb-teacher">负责人</td>
				<td class="tb-long-time">日期</td>
			<tr>
			<!--#for(Order order : orders)-->
			<tr>
				<td><a href="yueyogaAdmin/toMemberGoods.jhtml?id=${order.member.memberid}">${order.orderId}</a></td>
				<td>${order.member.name}</td>
				<td>${order.goodsName}</td>
				<td>${order.goodsPrice}</td>
				<td>${order.goodsCount}</td>
				<td>${order.discount}</td>
				<td>${order.money}</td>
				<td>${order.ud.name}</td>
				<td>${order.inputTime.format("yyyy-MM-dd")}</td>
			</tr>
			<!--#end-->
		</table>
		<div>
			<ul class="pagination">
				<li><a href="javascript:void(0);" onclick="goToPage(2,1)">首页</a></li>
				<!-- #if(pageNo1==1) -->
				<li class="disabled"><a href="javascript:void(0);">上一页</a></li>
				<!-- #else -->
				<li><a href="javascript:void(0);" onclick="goToPage(2,${prePageNo1})">上一页</a></li>
				<!-- #end -->
				<!-- #if(pageNo1==totalPages1) -->
				<li class="disabled"><a href="javascript:void(0);">下一页</a></li>
				<!-- #else -->
				<li><a href="javascript:void(0);" onclick="goToPage(2,${nextPageNo1})">下一页</a></li>
				<!-- #end -->
				<li><a href="javascript:void(0);" onclick="goToPage(2,${totalPages1})">尾页</a></li>
				<li><a>第<input id="txtPageNumber1" value="${pageNo1}" onkeydown="this.value=this.value.replace(/\D/g,'')" onkeyup="changePage(2,this.value)"
						onafterpaste="this.value=this.value.replace(/\D/g,'')" type="text" />页~&nbsp;共 ${totalPages1}&nbsp;页/${totalResults1}条
				</a></li>
			</ul>
		</div>
		<!-- #else -->
		
		<!-- #end -->
	</div>
</div>
<form class="form-horizontal" role="form" name="form_goods" action="yueyogaAdmin/saveGoodsCounts.jhtml" method="post">
	<div id="div_inventory" class="panel-dialog-gzjl panel-radius-search-all" style="display: none">
		<div class="panel-heading panel-result-title">
			<h3 class="panel-title">指定库存</h3>
		</div>
		<br> <label for="txtOldInventory" class="col-sm-1 control-label">原库存</label>
		<div class="col-sm-8">
			<input type="text" class="form-control" name="oldCounts" id="txtOldInventory" value=""  readonly> <input type="hidden" id="goodId" name="goodId" value="" />
		</div>
		<br> <br> <br> <label for="txtInventory" class="col-sm-1 control-label">新增库存</label>
		<div class="col-sm-8">
			<input type="text" class="form-control" name="counts" id="txtInventory" value="" >
		</div>
		<br> <br>
		<div class="panel-btn-search" style="text-align: right; margin-right: 70px;">
			<button type="button" id="btn_save" class="btn-adet-default" style="margin-right: 77px;">保存</button>
			&nbsp;&nbsp;&nbsp;
			<button type="button" id="btn_close" class="btn-adet-default">取消</button>
		</div>
	</div>
</form>
<script type="text/javascript">
	$(function() {
		 $("#btn_add").click(function(){
			 window.location.href="yueyogaAdmin/toAddGoods.jhtml";
		 });
		 var ids = [];
		//修改
		$("#btn_edit").click(function() {
			$('input[name="chk_name"]:checked').each(function() {
				ids.push($(this).val());
			});
			if (ids.length==1) {
				window.location.href = "yueyogaAdmin/toEditGoods.jhtml?goodsId="+ids;
			} else {
				alert("请选择一行进行编辑!");
			}
			ids = [];
		});
		//删除
		$("#btn_delete").click(function() {
			$('input[name="chk_name"]:checked').each(function() {
				ids.push($(this).val());
			});
			if(ids.length > 0){
				confirm("确定要删除吗", function() {
					this.close();
					var url = "yueyogaAdmin/deleteGoodsByIds.jhtml?chkIds="+ids;
					var d = wait("正在删除，请稍候...");
					$.post(url,function(msg) {
						if (msg == "true") {
							d.content("删除成功");
							setTimeout(function() {
								d.close().remove();
							}, 300);
							document.goodsForm.submit();
						} else {
							d.close();
							error("删除失败!");
						}
					});
				});
			}else{
				alert("请选择要删除的记录!");
			}
		});
		//--全选`反选
		$("#chkallIds").click(function() {
			if (this.checked) {
				$("input[name='chk_name']").each(function() {
					this.checked = true;
				});
			} else {
				$("input[name='chk_name']").each(function() {
					this.checked = false;
				});
			}
		}); 
		//指定库存
		
		//全选反选
		$("#chkallIds").click(function() {
					$(":input[name='chk_name']").prop("checked",
							$(this).prop("checked"));
				});
		$(".pro_ul li").click(function() {
			var aId = $(this).attr("id");
			var proId = "products";
			var orderId = "orders";
			var divPro = "#div_" + proId;
			var divOrder = "#div_" + orderId;
			var id = aId.split("_")[2];
			if (id == proId) {
				$(this).addClass("active");
				$("#pro_li_orders").removeClass("active");
				$("#goodsList").show();
				$("#product_search_cdts").show();
				$("#order_search_cdts").hide();
				$("#goodsOrderList").hide();
				$("#product_operator").show();
				document.goodsForm.submit();
			} else if (id == orderId) {
				$(this).addClass("active");
				$("#pro_li_products").removeClass("active");
				$("#goodsOrderList").show();
				$("#goodsList").hide();
				$("#product_search_cdts").hide();
				$("#order_search_cdts").show();
				$("#product_operator").hide();
				document.goodsOrderForm.submit();
			}
		});
	});
	function changePage(searchType,value) {
		value = value * 1;
		var totalPages = 0;
		if(searchType==2){
			$("#txtPageNumber1").val(value);
			totalPages = '${totalPages1}';
		}else{
			$("#txtPageNumber").val(value);
			totalPages = '${totalPages}';
		}
		if (value > totalPages) {
			value = totalPages;
		} else if (value < 1) {
			value = 1;
		}
		goToPage(value);
	}
	function goToPage(searchType,value){
		if(searchType=='2'){
			$("#hidOrderPageNo").val(value);
			document.goodsOrderForm.submit();
		}else{
			$("#hidPageNo").val(value);
			document.goodsForm.submit();
		}
	}
	$("#btn_inventory").click(function (){
		var chks = $('input[name="chk_name"]:checked');
		var goodId = chks.val();
		if (chks.length == 1) {
			$("#div_inventory").show();
			var counts = $("#td_"+chks.val()).text();
			$("#txtOldInventory").val(counts);
			$("#goodId").val(goodId);
		} else {
			alert("请选择一条记录指定库存");
		}
	});
	$("#btn_close").click(function (){
		$("#txtInventory").val("");
		$("#div_inventory").hide();
	});
	$("#btn_save").click(function (){
		var counts = $("#txtInventory").val();
		var isNumber = /^\+?[1-9][0-9]*$/;
		var v = !isNumber.test(counts);
		//var v = isNaN(counts);
		if (v) {
			$("#div_inventory").hide();
			var al = alert("请确认指定库存数值!");
			setTimeout(function(){
				al.close().remove();
				$("#div_inventory").show();
			},1000);
		}
		else{
			document.form_goods.submit();
		}
	});
</script>